** Table 6: Repo dispersion and the pass-through to lending rates

clear

** Loading data
*cd // *Your directory path goes here* //

* Step1: Load data on borrowing rates from the ECB’s monetary financial institutions (MFI) interest rate statistics
*More info here: https://www.ecb.europa.eu/press/pr/stats/mfi/html/index.en.html
*We employ data for non-financial corporate borrowing as well as bank interest rates on new loans to households for house purchases with an initial rate fixation period of between one and five years. 
import excel .\Data\MFILendingRates_Pseudo.xlsx, sheet("Sheet1") firstrow allstring clear // use pseudodata
gen dateSTATA = date(substr(date,1,11),"MDY")
format dateSTATA %td
drop date
gen year=year(dateSTATA) 
gen month=month(dateSTATA)
rename Country country
destring Rate, replace

* Step 2: Add information on EONIA
* download daily data from, for example, Bloomberg / Thomson Reuters and replace code below:
gen EONIA=0.5 // create pseudodata

* Step 3: Add information on DFR
* download data on the DFR (see: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/key_ecb_interest_rates/html/index.en.html) and replace code below:
gen DFR=0.5 // create pseudodata

* Step 4: Calculate daily, average GC rate
preserve
clear
import excel .\Data\GC_DailyAverages_Pseudo.xlsx, firstrow allstring
gen dateSTATA = date(substr(refdate,1,11),"MDY")
format dateSTATA %td
gen year = year(dateSTATA) 
gen month = month(dateSTATA)
drop refdate dateSTATA
generate dateSTATA = mdy(month, 1, year)
format dateSTATA %td
destring volweightedrate volsum ecbaccesslender, replace
sort country dateSTATA
by country dateSTATA: egen meanGCRate = wtmean(volweightedrate), weight(volsum)
keep meanGCRate country dateSTATA
duplicates drop
save .\Data\MeanGCRatesByCountry.dta, replace
restore
merge m:1 dateSTATA country using .\Data\MeanGCRatesByCountry.dta
keep if _merge==3
drop _merge
erase .\Data\MeanGCRatesByCountry.dta

gen QE = 0
replace QE = 1 if dateSTATA>date("08.03.2015","DMY")

* Step 5: Import dispersion index
preserve
clear
import excel .\Data\DispersionIndex_Pseudo.xlsx, firstrow allstring
gen dateSTATA = date(substr(refdate,1,11),"MDY")
format dateSTATA %td
drop refdate
destring SpecialIndex GCIndex, replace
save .\Data\DispersionIndexMonthly.dta, replace
restore
merge m:1 dateSTATA using .\Data\DispersionIndexMonthly.dta
keep if _merge==3
drop _merge
erase .\Data\DispersionIndexMonthly.dta

* Step 6: Calculate changes:
bysort country Variable (dateSTATA): gen delrate = Rate[_n]-Rate[_n-1]
bysort country Variable (dateSTATA): gen delMMRate = EONIA[_n]-EONIA[_n-1]
encode(country), gen(CountryCat)

* Step 6: Calculate additional regression inputs:
egen GCIndexM = median(GCIndex)
gen D_DK_GC = 0
replace D_DK_GC = 1 if GCIndex > GCIndexM
egen SpecialIndexM = median(SpecialIndex)
gen D_DK_Special = 0
replace D_DK_Special =1 if SpecialIndex > SpecialIndexM
gen D_DK_Repo = 0
replace D_DK_Repo = 1 if D_DK_Special==1|D_DK_GC==1

** Regressions

eststo clear
eststo R1a, title("NFC"): reghdfe delrate delMMRate i.D_DK_GC#c.delMMRate i.D_DK_Special#c.delMMRate if Variable=="NonFinCorpBorrowing", nocons absorb(CountryCat#year) vce(cluster year) noomitted
eststo R1b, title("NFC"): reghdfe delrate delMMRate i.D_DK_Repo#c.delMMRate if Variable=="NonFinCorpBorrowing", nocons absorb(CountryCat#year) vce(cluster year) noomitted
eststo R1c, title("Housing"): reghdfe delrate delMMRate i.D_DK_GC#c.delMMRate i.D_DK_Special#c.delMMRate if Variable=="HousingLoansNew", nocons absorb(CountryCat#year) vce(cluster year) noomitted
eststo R1d, title("Housing"): reghdfe delrate delMMRate i.D_DK_Repo#c.delMMRate if Variable=="HousingLoansNew", nocons absorb(CountryCat#year) vce(cluster year) noomitted
